// Package expressinfoin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package expressinfoin

import (
	"context"
	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/errors/gerror"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// ExpressInfoUpdateFields 修改物流信息字段过滤
type ExpressInfoUpdateFields struct {
	Recipient            string      `json:"recipient"          dc:"收件人"`
	ShippingProvinceId   int64       `json:"shippingProvinceId" dc:"省市区id"`
	ShippingAddress      string      `json:"shippingAddress"    dc:"详细地址"`
	Tel                  string      `json:"tel"                dc:"联系方式"`
	Status               int         `json:"status"             dc:"状态"`
	ExpressCompany       int         `json:"expressCompany"     dc:"快递公司"`
	ExpressNumber        string      `json:"expressNumber"      dc:"快递单号"`
	OperatorId           int64       `json:"operatorId"         dc:"操作发货人"`
	DispatchTime         *gtime.Time `json:"dispatchTime"       dc:"发货时间"`
	ShippingProvinceName string      `json:"shippingProvinceName" dc:"省市区名称"`
	MemberCardId         int         `json:"memberCardId"         dc:"会员卡ID"`
}

// ExpressInfoInsertFields 新增物流信息字段过滤
type ExpressInfoInsertFields struct {
	OrderUid string `json:"orderUid"                   dc:"订单uid"`
	//StoreId            int64       `json:"storeId"                    dc:"商家id"`
	ProductId            int64       `json:"productId"                  dc:"产品id"`
	UserId               int64       `json:"userId"                     dc:"购买者id"`
	Recipient            string      `json:"recipient"          dc:"收件人"`
	ShippingProvinceId   int64       `json:"shippingProvinceId" dc:"省市区id"`
	ShippingAddress      string      `json:"shippingAddress"    dc:"详细地址"`
	Tel                  string      `json:"tel"                dc:"联系方式"`
	Status               int         `json:"status"             dc:"状态"`
	ExpressCompany       int         `json:"expressCompany"     dc:"快递公司"`
	ExpressNumber        string      `json:"expressNumber"      dc:"快递单号"`
	OperatorId           int64       `json:"operatorId"         dc:"操作发货人"`
	DispatchTime         *gtime.Time `json:"dispatchTime"       dc:"发货时间"`
	ShippingProvinceName string      `json:"shippingProvinceName" dc:"省市区名称"`
	MemberCardId         int         `json:"memberCardId"         dc:"会员卡ID"`
}

// ExpressInfoEditInp 修改/新增物流信息
type ExpressInfoEditInp struct {
	entity.ExpressInfo
	IsConfirm bool `json:"isConfirm" dc:"是否确认发货"`
}

func (in *ExpressInfoEditInp) Filter(ctx context.Context) (err error) {
	// 验证收件人
	if err := g.Validator().Rules("required").Data(in.Recipient).Messages("收件人不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证省市区id
	if err := g.Validator().Rules("required").Data(in.ShippingProvinceId).Messages("省市区id不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证详细地址
	if err := g.Validator().Rules("required").Data(in.ShippingAddress).Messages("详细地址不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证联系方式
	if err := g.Validator().Rules("required").Data(in.Tel).Messages("联系方式不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证状态
	if err := g.Validator().Rules("required").Data(in.Status).Messages("状态 不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证快递公司
	if err := g.Validator().Rules("required").Data(in.ExpressCompany).Messages("快递公司不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	//// 验证快递单号
	//if err := g.Validator().Rules("required").Data(in.ExpressNumber).Messages("快递单号不能为空").Run(ctx); err != nil {
	//	return err.Current()
	//}

	//// 验证操作发货人
	//if err := g.Validator().Rules("required").Data(in.OperatorId).Messages("操作发货人不能为空").Run(ctx); err != nil {
	//	return err.Current()
	//}

	return
}

type ExpressInfoEditModel struct{}

// ExpressInfoDeleteInp 删除物流信息
type ExpressInfoDeleteInp struct {
	Id interface{} `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *ExpressInfoDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type ExpressInfoDeleteModel struct{}

// ExpressInfoViewInp 获取指定物流信息信息
type ExpressInfoViewInp struct {
	Id int64 `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *ExpressInfoViewInp) Filter(ctx context.Context) (err error) {
	return
}

type ExpressInfoViewModel struct {
	Id                   int64       `json:"id"                 dc:"id"`
	OrderUid             string      `json:"orderUid"           dc:"订单uid"`
	Recipient            string      `json:"recipient"          dc:"收件人"`
	ShippingProvinceId   int64       `json:"shippingProvinceId" dc:"省市区id"`
	ShippingAddress      string      `json:"shippingAddress"    dc:"详细地址"`
	Tel                  string      `json:"tel"                dc:"联系方式"`
	Status               int         `json:"status"             dc:"状态"`
	ExpressCompany       int         `json:"expressCompany"     dc:"快递公司"`
	ExpressNumber        string      `json:"expressNumber"      dc:"快递单号"`
	OperatorId           int64       `json:"operatorId"         dc:"操作发货人"`
	CreatedAt            *gtime.Time `json:"createdAt"          dc:"创建时间"`
	DispatchTime         *gtime.Time `json:"dispatchTime"       dc:"发货时间"`
	UpdatedAt            *gtime.Time `json:"updatedAt"          dc:"更新时间"`
	OrderTraceId         string      `json:"orderTraceId"       dc:"交易ID(流水号)"`
	StoreName            string      `json:"storeName"         dc:"门店名称"`
	ProductName          string      `json:"productName"        dc:"商品名称"`
	ProductMainImage     *gjson.Json `json:"productMainImage"  dc:"商品主图"`
	ShippingProvinceName string      `json:"shippingProvinceName" dc:"省市区名称"`
	AdminMemberRealName  string      `json:"adminMemberRealName"  dc:"操作发货人姓名"`
	AdminMemberAvatar    string      `json:"adminMemberAvatar"    dc:"操作发货人头像"`
	AdminMemberUsername  string      `json:"adminMemberUsername"  dc:"操作发货人账号"`
	AdminMemberMobile    string      `json:"adminMemberMobile"    dc:"操作发货人手机号"`
}

// ExpressInfoListInp 获取物流信息列表
type ExpressInfoListInp struct {
	form.PageReq
	Id            int64         `json:"id"            dc:"id"`
	OrderUid      string        `json:"orderUid"      dc:"订单uid"`
	UserId        int64         `json:"userId"        dc:"购买者id"`
	Status        int           `json:"status"        dc:"状态"`
	ExpressNumber string        `json:"expressNumber" dc:"快递单号"`
	CreatedAt     []*gtime.Time `json:"createdAt"     dc:"创建时间"`
}

func (in *ExpressInfoListInp) Filter(ctx context.Context) (err error) {
	return
}

type ExpressInfoListModel struct {
	Id                 int64       `json:"id"                 dc:"id"`
	OrderUid           string      `json:"orderUid"           dc:"订单uid"`
	Recipient          string      `json:"recipient"          dc:"收件人"`
	ShippingProvinceId int64       `json:"shippingProvinceId" dc:"省市区id"`
	ShippingAddress    string      `json:"shippingAddress"    dc:"详细地址"`
	Tel                string      `json:"tel"                dc:"联系方式"`
	Status             int         `json:"status"             dc:"状态"`
	ExpressCompany     int         `json:"expressCompany"     dc:"快递公司"`
	ExpressNumber      string      `json:"expressNumber"      dc:"快递单号"`
	OperatorId         int64       `json:"operatorId"         dc:"操作发货人"`
	CreatedAt          *gtime.Time `json:"createdAt"          dc:"创建时间"`
	DispatchTime       *gtime.Time `json:"dispatchTime"       dc:"发货时间"`
	UpdatedAt          *gtime.Time `json:"updatedAt"          dc:"更新时间"`
	OrderTraceId       string      `json:"orderTraceId"       dc:"交易ID(流水号)"`
	//StoreName           string      `json:"storeName"         dc:"门店名称"`
	ProductName         string      `json:"productName"        dc:"商品名称"`
	ProductMainImage    *gjson.Json `json:"productMainImage"  dc:"商品主图"`
	AdminMemberRealName string      `json:"adminMemberRealName"  dc:"操作发货人姓名"`
	AdminMemberAvatar   string      `json:"adminMemberAvatar"    dc:"操作发货人头像"`
	AdminMemberUsername string      `json:"adminMemberUsername"  dc:"操作发货人账号"`
}

// ExpressInfoExportModel 导出物流信息
type ExpressInfoExportModel struct {
	Id       int64  `json:"id"                 dc:"id"`
	OrderUid string `json:"orderUid"           dc:"订单uid"`
	//StoreId            int64       `json:"storeId"            dc:"商家id"`
	ProductId          int64       `json:"productId"          dc:"产品id"`
	UserId             int64       `json:"userId"             dc:"购买者id"`
	Recipient          string      `json:"recipient"          dc:"收件人"`
	ShippingProvinceId int64       `json:"shippingProvinceId" dc:"省市区id"`
	ShippingAddress    string      `json:"shippingAddress"    dc:"详细地址"`
	Tel                string      `json:"tel"                dc:"联系方式"`
	Status             int         `json:"status"             dc:"状态"`
	ExpressCompany     int         `json:"expressCompany"     dc:"快递公司"`
	ExpressNumber      string      `json:"expressNumber"      dc:"快递单号"`
	OperatorId         int64       `json:"operatorId"         dc:"操作发货人"`
	CreatedAt          *gtime.Time `json:"createdAt"          dc:"创建时间"`
	DispatchTime       *gtime.Time `json:"dispatchTime"       dc:"发货时间"`
	UpdatedAt          *gtime.Time `json:"updatedAt"          dc:"更新时间"`
	OrderTraceId       string      `json:"orderTraceId"       dc:"交易ID(流水号)"`
	StoreName          string      `json:"storeName"          dc:"门店名称"`
	ProductName        string      `json:"productName"        dc:"商品名称"`
	ProductMainImage   *gjson.Json `json:"productMainImage"   dc:"商品主图"`
}

type ExpressInfoChangeStatusInp struct {
	Id                 int64  `json:"id" v:"required#id不能为空" dc:"id"`
	ExpressCompany     int8   `json:"expressCompany" v:"required#物流公司代码不能为空"  dc:"物流公司代码"`
	ExpressNumber      string `json:"expressINumber" v:"required#快递单号不能为空"  dc:"快递单号"`
	Recipient          string `json:"recipient"          v:"required#收件人不能为空" description:"收件人"`
	ShippingProvinceId int64  `json:"shippingProvinceId" v:"required#省市区id不能为空" description:"省市区id"`
	ShippingAddress    string `json:"shippingAddress"    v:"required#详细地址不能为空" description:"详细地址"`
	Tel                string `json:"tel"                v:"required#联系方式不能为空" description:"联系方式"`
}

func (in *ExpressInfoChangeStatusInp) Filter(ctx context.Context) (err error) {
	if !validate.InSlice(consts.ExpressSetList, int(in.ExpressCompany)) {
		err = gerror.New("物流公司代码不正确")
	}
	return
}

type ExpressInfoChangeStatusModel struct{}
